﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BleQua.Controls.Options {
	/// <summary>
	/// Interaction logic for AccountsOptionControl.xaml
	/// </summary>
	public partial class AccountsOptionsControl : UserControl {
		public AccountsOptionsControl( ) {
			InitializeComponent( );
			this.LB_Accounts.ItemsSource = Core.Main.Current.Accounts;
			this.LB_Accounts_SelectionChanged(this.LB_Accounts, null);
		}

		public void OK_Click(object sender, RoutedEventArgs e) {

		}
		public void Cancel_Click(object sender, RoutedEventArgs e) {

		}
		public void Apply_Click(object sender, RoutedEventArgs e) {

		}

		private void Up_Click(object sender, RoutedEventArgs e) {
			App.Core.Accounts.MoveUpItem(this.LB_Accounts.SelectedIndex);
			this.LB_Accounts_SelectionChanged(this.LB_Accounts, null);
		}
		private void Down_Click(object sender, RoutedEventArgs e) {
			App.Core.Accounts.MoveDownItem(this.LB_Accounts.SelectedIndex);
			this.LB_Accounts_SelectionChanged(this.LB_Accounts, null);
		}
		private void New_Click(object sender, RoutedEventArgs e) {
			BleQua.Windows.Dialogs.AccountWindow AW = new Windows.Dialogs.AccountWindow( );
			AW.ShowDialog( );
		}
		private void Edit_Click(object sender, RoutedEventArgs e) {
			if (this.LB_Accounts.SelectedIndex != -1) {
				BleQua.Windows.Dialogs.AccountWindow AW = new Windows.Dialogs.AccountWindow( );
				AW.ShowDialog(this.LB_Accounts.SelectedItem);
			}
		}
		private void Delete_Click(object sender, RoutedEventArgs e) {
			if (this.LB_Accounts.SelectedIndex != -1) {
				App.Core.Accounts.RemoveAt(this.LB_Accounts.SelectedIndex);
			}
		}
		private void ChangePassword_Click(object sender, RoutedEventArgs e) {
			if (this.LB_Accounts.SelectedIndex != -1) {
				BleQua.Windows.Dialogs.ChangePasswordWindow CPW = new Windows.Dialogs.ChangePasswordWindow( );
				CPW.ShowDialog(this.LB_Accounts.SelectedItem);
			}
		}

		#region Binding events
		private void LB_Accounts_SelectionChanged(object sender, SelectionChangedEventArgs e) {
			if (this.LB_Accounts.SelectedIndex >= 0) {
				this.B_Edit.IsEnabled = true;
				this.B_Delete.IsEnabled = true;
				this.B_ChangePassword.IsEnabled = true;
				this.B_Up.IsEnabled = (this.LB_Accounts.SelectedIndex > 0);
				this.B_Down.IsEnabled = (this.LB_Accounts.SelectedIndex < this.LB_Accounts.Items.Count - 1);
			} else {
				this.B_Edit.IsEnabled = false;
				this.B_Delete.IsEnabled = false;
				this.B_ChangePassword.IsEnabled = false;
				this.B_Up.IsEnabled = false;
				this.B_Down.IsEnabled = false;
			}
		}
		#endregion
	}
}
